package com.tyqx.hashchainbiz.controller.mission.productIn;

import com.tyqx.hashchainbean.module.ProductIn;
import com.tyqx.hashchainbean.vo.*;
import com.tyqx.hashchainbiz.service.ProductInService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "入库物资")
@RestController
@RequestMapping("/productIn")
@CrossOrigin
public class ProductInController {

    @Resource
    private ProductInService productInService;

    @RequestMapping(value="/saveProductIn", method = RequestMethod.POST)
    @ResponseBody
    public String saveProductIn(@RequestBody ProductInVO productInVO) throws Exception {

        String msg="";
        ProductIn productIn=new ProductIn();
        //productIn.setAttachment(productInVO.getAttachment());
        productIn.setDonateId(productInVO.getDonateId());
        productIn.setDonator(productInVO.getDonator());
        productIn.setInId(productInVO.getInId());
        productIn.setInName(productInVO.getInName());
        productIn.setInTime(productInVO.getInTime());
        productIn.setInUnit(productInVO.getInUnit());
        productIn.setProductType(productInVO.getProductType());
        productIn.setReceiver(productInVO.getReceiver());
        productIn.setShipper(productInVO.getShipper());
        productIn.setUserName(productInVO.getUserName());
        productIn.setVerification(productInVO.getVerification());



        if(productInService.productIn(productIn)>0){
            msg="入库物资成功";
        }else{
            msg="入库物资失败";
        }
        return msg;
    }

    @RequestMapping(value="/getProductInById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProductIn> getProductInById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return productInService.getProductInById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getProductInByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProductIn> getProductInByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return productInService.getProductInByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
